<!-- 后结算模块-财务管理-销售管理-销售单响应/发货 -->
<template>
  <div class="auth-product distributor-settlement-change-box">
    <el-container class="change-container is-vertical">
      <record-info
        class="custom-info"
        :record-form="saleCommonForm"
        :record-data="headerInfo">
        <template slot="recordInfoslot">
          <tabs
            v-if="isDeliver"
            class="tabs"
            :tabs-arr="deliverGoodsTabsArr"
            @returnIndex="tabsHandle"
          />
          <SearchForm
            label-width="66px"
            :data="activeSearch"
            :compact-data="activeSearch.slice(0,2)"
            show-collapse
            @searchForm="searchForm"
            @resetForm="resetForm"
            :submit-loading="tableLoading"
          />
          <div
            v-if="!tabIndex"
            class="solt-info">
            <span class="left-span">
              销售产品总数
              <span class="right-span">{{ headerInfo.prodTotalCount }}</span>
            </span>
            <span>
              品种数
              <span>{{ headerInfo.prodTypeCount }}</span>
            </span>
            <span>
              金额合计 （元）:
              <span>
                <span class="price">{{ headerInfo.orderAmount | getFormatterPrice }}</span>
              </span>
            </span>
            <span v-if="isDeliver">选中产品总数：<span>{{ cacheProData.prodTotalCount || 0 }}</span></span>
            <span v-if="isDeliver">选中品种数：<span>{{ cacheProData.prodVarietyCount || 0 }}</span></span>
            <span v-if="isDeliver">选中金额合计（元）：<span style="color:red;">{{ cacheProData.cacheAmountTotal || 0 | getFormatterPrice }}</span></span>
            <el-button
              v-if="isDeliver && activeList"
              size="mini"
              type="primary"
              class="batch-btn"
              :disabled="activeList.length ? false : true"
              @click="batchAddInvoice"
            >上传发票</el-button>
            <el-button
              v-if="isResponse"
              size="mini"
              type="primary"
              class="batch-btn"
              @click="batchSelectionSupplier"
            >批量选择供应商</el-button>
          </div>
        </template>
      </record-info>
      <div v-if="!tabIndex">
        <el-editable
          ref="multipleTable"
          class="hospital-edit-box"
          :data="activeList"
          :key="activeIndex"
          height="500"
          v-loading="tableLoading"
          :columns="activeColumns"
          @select="changeSelect"
          @select-all="changeSelectAll"
        >
          <!-- 选择供应商 -->
          <template
            slot="default-supplierName"
            slot-scope="scope">
            <el-select
              v-if="isResponse"
              v-model="scope.row.supplierName"
              filterable
              clearable
              :filter-method="getSupplierList"
              @change="setSupplierInfo($event, scope.row)"
              placeholder="请选择"
            >
              <!--
              @focus="getSupplierList(scope.row.supplierName)" -->
              <el-option
                v-for="item in supplierOptions"
                :key="item.companyId"
                :label="item.companyName"
                :value="item.companyId"
              />
            </el-select>
            <span v-else>{{ scope.row.supplierName }}</span>
          </template>
          <!-- 注册证号/备案证号 -->
          <template
            slot="default-pssRegistrationNumber"
            slot-scope="scope">
            <el-button
              :disabled="!scope.row.pssRegistrationNumber||!scope.row.pssRegistrationId"
              v-html="regisNoButton(scope.row, 'pssRegistration')"
              @click="showPdfRegistion(scope.row.pssRegistrationId)"
              type="text"
            />
          </template>
          <!-- 发票详情 -->
          <template
            slot="default-mplatInvoiceStatus"
            slot-scope="scope">
            <!-- <el-button
              v-if="scope.row.mplatInvoiceStatus === 1"
              @click="toLookDetails()"
              type="text">查看详情</el-button> -->
            <span
              v-if="scope.row.mplatInvoiceStatus === 2"
              style="color:red;">发票作废</span>
            <span
              v-if="scope.row.mplatInvoiceStatus === 3"
              style="color:red;">查无此票</span>
            <span v-if="scope.row.mplatInvoiceStatus === 4">查验中</span>
            <span v-if="!scope.row.mplatInvoiceStatus">待上传</span>
          </template>
          <!-- 发票影像 -->
          <template
            slot="default-invoiceUrl"
            slot-scope="scope">
            <div style="display:flex; justify-content: center;">
              <el-image
                v-if="scope.row.invoiceUrl"
                @click="toLookDetails(scope.row)"
                style="width: 23px; height: 16.6px;"
                :src="imageicon"
              />
            </div>
          </template>
          <template
            slot="default-hspRegistrationNumber"
            slot-scope="scope">
            <el-button
              :disabled="!scope.row.hspRegistrationNumber||!scope.row.hspRegistrationId"
              v-html="regisNoButton(scope.row, 'hspRegistration')"
              @click="showPdfRegistion(scope.row.hspRegistrationId)"
              type="text"
            />
          </template>
        </el-editable>

        <el-pagination
          class="pagination"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="curPage"
          :page-sizes="PAGE_NUMBER"
          :page-size="pageSize"
          :layout="PAGINATION_LAYOUT"
          :total="totalElements"
        />
      </div>
      <div v-if="tabIndex">
        <div
          class="invoice-associated-box"
          v-for="(item,index) in invoiceAssociatedList"
          :key="index"
        >
          <div class="invoice-associated-info">
            <div class="left-box">
              <p>
                发票号：{{ item.invoiceNo }}
                <el-button
                  type="text"
                  @click="toLookDetails(item)">查看详情</el-button>
              </p>
              <p v-if="item.mplatInvoiceStatus === 1">
                发票状态：验真通过
                <el-button
                  type="text"
                  @click="toLookDetails(item)">查看影像</el-button>
              </p>
              <p>
                发票价税合计（元）：
                <span style="color:red;">{{ item.totalPriceTax | getFormatterPrice }}</span>
              </p>
              <p>
                关联产品价税合计（元）：
                <span style="color:red;">{{ item.detailAmountCount | getFormatterPrice }}</span>
              </p>
            </div>
            <div>
              <el-button
                v-if="item.invoiceSource === 2"
                size="mini"
                type="primary"
                @click="toCancelRelevance(2)">批量取消关联</el-button>
              <el-button
                v-if="item.invoiceSource === 1"
                size="mini"
                type="primary"
                @click="toLookDetails(item)">上传影像</el-button>
            </div>
          </div>

          <el-editable
            class="hospital-edit-box"
            :data="item.productDetail.content"
            :key="activeIndex"
            height="200"
            v-loading="tableLoading"
            :columns="invoiceAssociatedColumns"
            @selection-change="changeSelectMultiple"
          >
            <!-- 操作 -->
            <template
              slot="default-action"
              slot-scope="scope">
              <el-button
                :disabled="scope.row.invoiceSource === 1"
                @click="toCancelRelevance(1,scope.row)"
                type="text">取消关联</el-button>
            </template>
          </el-editable>
          <el-pagination
            class="pagination"
            @size-change="handleSizeChangeMultiple($event,item.productDetail,index)"
            @current-change="handleCurrentChangeMultiple($event,index)"
            :current-page="item.productDetail.number"
            :page-size="item.productDetail.Asize"
            :layout="PAGINATION_LAYOUT"
            :page-sizes="PAGE_NUMBER"
            :total="item.productDetail.totalElements"
          />
        </div>
      </div>
      <invoice-details
        :display-or-not="displayOrNotDetails"
        :invoice-url="activeInvoiceUrl"
        :invoice-no="activeInvoiceNo"
        @cancelDialog="cancelDialog" />
      <el-dialog
        title="批量选择供应商"
        :visible.sync="isBatchSelectionSupplier"
        width="500px"
        @close="handleCloseBatchSelectionSupplier">
        <div class="batch-selection-supplier">
          <span> 供应商 </span>
          <el-select
            v-model="batchSelectionSupplierId"
            filterable
            clearable
            :filter-method="getSupplierList"
            placeholder="请选择"
          >
            <!--
            @focus="getSupplierList(scope.row.supplierName)" -->
            <el-option
              v-for="item in supplierOptions"
              :key="item.companyId"
              :label="item.companyName"
              :value="item.companyId"
            />
          </el-select>
        </div>
        <span
          slot="footer"
          class="dialog-footer">
          <el-button @click="handleCloseBatchSelectionSupplier">
            <i class="el-icon-circle-close"/>
            取 消</el-button>
          <el-button
            type="primary"
            @click="toBatchSelectionSupplier">
            <i class="el-icon-circle-check"/>
            确 定</el-button>
        </span>
      </el-dialog>
    </el-container>
  </div>
</template>

<script>
import {
  saleCommonForm,
  statusArr,
  partResponseColumns,
  partWaitColumns,
  saleResponseSearchData,
  saleDeliverSearchData,
  invoiceAssociatedColumns
} from './const'
import { PAGE_NUMBER, PAGINATION_LAYOUT } from '@const/common'
import RecordInfo from '@/moduleComponents/beforeSettle/distributorSide/purchasingManagement/record'
import { attrItemList } from '@const/orderCenterApi'
import {
  distributorSaleConfrim,
  distributorSaleOrderDetail,
  distributorSaleOrderOperate,
  distributorSaleItemUpdate,
  distributorSaleWait,
  partnerList,
  relevanceList,
  cancelRelevance,
  cacheInvoiceOrderItemInfo,
  relevancePageRelList,
  settleGetAmountofCache
} from '@const/beforeSettleApi'
import ElEditable from '@components/el-editable'
import SearchForm from '@components/businesscomponents/search'
import { cloneDeep, isObject, hasIn } from 'lodash'
import { getFormatterPrice } from '@const/filter'
import { getCertificate } from '@const/productCenterApiV2'
import tabs from '@components/tabs/index.vue'
import invoiceDetails from '@/moduleComponents/beforeSettle/invoiceDetails/index.vue'
export default {
  components: { ElEditable, RecordInfo, SearchForm, tabs, invoiceDetails },
  data () {
    return {
      imageicon: require('@assets/icon/beforeSettle/imageicon.png'),
      id: this.$route.query.id,
      orderStatus: null,
      // 表格Loading
      tableLoading: false,
      batchDialogVisible: false,
      orderLists: [],
      selectList: [],
      // 搜索返回内容
      searchData: {},
      batchInvoiceForm: { invoiceNo: null },
      // 表头
      saleCommonForm,
      columnsLists: [partResponseColumns, partWaitColumns],
      searchColumnsLists: [saleResponseSearchData, saleDeliverSearchData],
      // 表单 详情展示内容-table
      curPage: 1, // 当前页
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      pageSize: PAGE_NUMBER[0], // 一页的数量
      totalElements: 0, // 总共的条数
      // 订单详情信息
      headerInfo: {},
      // 客商列表
      supplierOptions: [],

      deliverGoodsTabsArr: [
        { lab: '待关联发票', val: 0, badge: { value: null } },
        { lab: '已关联发票', val: 1, badge: { value: null } }
      ],
      invoiceAssociatedColumns,
      invoiceAssociatedList: [], // 已关联发票列表
      tabIndex: 0,
      // 查看发票详情
      displayOrNotDetails: false,
      activeInvoiceUrl: '',
      activeInvoiceNo: '',
      selectStatus: false,
      isBatchSelectionSupplier: false,
      batchSelectionSupplierId: '',
      cancelRelevanceList: [], // 取消关联选中的数据
      cacheProData: {}
      // invoiceStatusArr:['']
    }
  },
  filters: {
    getFormatterPrice
  },
  computed: {
    // 订单状态（0-全部，11-待响应，12-待发货，13-发货完成，14-已完成，15-已撤消，16-已拒绝）
    // 待响应
    isResponse () {
      return [11].includes(this.orderStatus)
    },
    // 待发货
    isDeliver () {
      return [12].includes(this.orderStatus)
    },
    activeIndex () {
      return [11].includes(this.orderStatus)
        ? 0
        : [12].includes(this.orderStatus)
          ? 1
          : null
    },
    activeSearch () {
      return this.searchColumnsLists[this.activeIndex] || []
    },
    activeColumns () {
      return this.columnsLists[this.activeIndex]
    },
    activeList () {
      return this.orderLists[this.activeIndex]
    }
  },
  mounted () {
    this.getOrderStatusById()
    this.getSupplierList()
  },
  methods: {
    _globalBtns () {
      // 订单状态（0-全部，11-待响应，12-待发货，13-发货完成，14-已完成，15-已撤消，16-已拒绝）
      // 11待响应: 拒绝  响应 响应并生成采购单
      // 12待发货: 确认发货
      let arr = [11].includes(this.orderStatus)
        ? [
          {
            type: 'danger',
            val: '拒绝',
            disabled: true,
            handle: this.rejectOrder
          },
          { type: 'primary', val: '暂存', handle: this.toStory },
          { type: 'primary', val: '响应', handle: this.response },
          {
            type: 'primary',
            val: '响应并生成采购单',
            handle: this.responseMakeOrders
          }
        ]
        : [12].includes(this.orderStatus)
          ? [{ type: 'primary', val: '确认发货', handle: this.toDeliver }]
          : []
      const btn = {
        type: 'btn',
        arr
      }
      this.$store.commit('changeLayoutHandle', btn)
    },
    // 获取缓存数据合计
    getSettleGetAmountofCache () {
      const url = settleGetAmountofCache
      const data = {
        orderId: this.id, // 订单id
        type: 'deliver'
      }
      this.$axios.$post(url, data).then(res => {
        if (res.code === '0') {
          const cacheProData = hasIn(res, 'payload') ? res.payload : {}
          this.cacheProData = cacheProData
        }
      })
        .catch(err => {
          console.log(err)
        })
    },
    // 已关联-上传影像
    uploadRelevance () {
      this.displayOrNotDetails = true
    },
    // 取消关联
    toCancelRelevance (type, data) {
      let params = []
      if (type === 1) {
        params = [data.orderItemId]
      } else {
        if (this.cancelRelevanceList.length === 0) {
          this.$message.warning('请选择需要取消的产品！')
          return
        }
        params = this.cancelRelevanceList.map(item => item.orderItemId)
      }
      this.$axios({
        method: 'post',
        url: cancelRelevance,
        data: params
      }).then(res => {
        if (res.data.code === '0') {
          this.getInitializationList()
        }
      })
    },
    // 查看发票详情
    toLookDetails (val) {
      this.activeInvoiceUrl = val.invoiceUrl
      this.activeInvoiceNo = val.invoiceNo
      this.displayOrNotDetails = true
    },
    cancelDialog (val) {
      this.activeInvoiceUrl = ''
      this.activeInvoiceNo = ''
      this.displayOrNotDetails = false
      // if(val){
      this.getInitializationList()
      // }
    },
    // 批量选择供应商
    batchSelectionSupplier () {
      if (this.selectList.length === 0) {
        this.$message.warning('请选择产品！')
      } else {
        this.isBatchSelectionSupplier = true
        this.batchSelectionSupplierId = this.headerInfo.defaultSupplierInfo.supplierId
      }
    },
    // 确定选择
    toBatchSelectionSupplier () {
      let name = ''
      this.supplierOptions.forEach(item => {
        if (item.companyId === this.batchSelectionSupplierId) {
          name = item.companyName
        }
      })
      this.selectList.forEach(item => {
        this.orderLists[0].forEach(it => {
          if (item.saleDetailId === it.saleDetailId) {
            this.$set(it, 'supplierId', this.batchSelectionSupplierId)
            this.$set(it, 'supplierName', name)
          }
        })
      })
      this.batchSelectionSupplierId = ''
      this.isBatchSelectionSupplier = false
      this.$refs.multipleTable.$refs.table.clearSelection()
      this.selectList = []
    },
    handleCloseBatchSelectionSupplier () {
      this.isBatchSelectionSupplier = false
    },
    // tabs切换处理事件
    tabsHandle (index) {
      this.tabIndex =
        this.deliverGoodsTabsArr[index].val === 'null'
          ? null
          : this.deliverGoodsTabsArr[index].val
      this.curPage = 1
      if (this.tabIndex) {
        this.getInitializationList()
      } else {
        this.getList()
      }
    },
    // 获取已关联发票明细（初始化调用）
    getInitializationList () {
      let data = {
        page: 1,
        pageSize: 20,
        saleOrderId: this.id,
        ...this.searchData
      }
      this.$axios({
        method: 'post',
        url: relevanceList,
        data: data
      }).then(res => {
        this.invoiceAssociatedList = res.data.payload || []
      })
    },
    // 获取已关联发票明细（分页调用）

    // 获取产品信息
    async getSupplierList (val = '') {
      const params = {
        partnership: 'provider',
        name: val,
        registered: 2
      }
      const data = await this.$axios.$get(partnerList, { params })
      if (data.code === '0') {
        this.supplierOptions = hasIn(data, 'payload') ? data.payload || [] : []
      }
    },
    // 选中供应商
    setSupplierInfo (value, row) {
      let itemArr = this.supplierOptions.filter(col => {
        return Object.is(col.companyId, value)
      })
      let item = itemArr[0] || {}
      item = {
        supplierName: item.companyName,
        supplierId: item.companyId
      }
      Object.assign(row, item)
    },
    async changeStatus (operateType, isStory = false) {
      const isHasSupplierId = data => data.supplierId || isStory
      const supplierInfoList = this.orderLists[0]
        .filter(isHasSupplierId)
        .map(({ supplierName, supplierId, saleDetailId }) => {
          return {
            supplierName,
            supplierId,
            orderItemId: saleDetailId
          }
        })
      const body = {
        saleOrderId: this.id,
        operateType,
        supplierInfoList
      }
      if (!isStory && supplierInfoList.length < this.orderLists[0].length) {
        this.$message.warning('请选择供应商')
      }
      const data = await this.$axios.$post(distributorSaleOrderOperate, body)
      if (data.code === '0') {
        this.$message.success('操作成功')
        return data.code
      }
    },
    // 拒绝
    async rejectOrder () {
      const code = await this.changeStatus(1)
      code === '0' && this.$router.go(-1)
    },
    // 响应
    async response () {
      const code = await this.changeStatus(3)
      code === '0' && this.$router.go(-1)
    },
    // 更新供应商
    async toStory () {
      await this.changeStatus(2, true)
      this.getList()
    },
    // 响应并生成采购单
    async responseMakeOrders () {
      const code = await this.changeStatus(4)
      // 跳转采购列表
      code === '0' &&
        this.$router.push(
          '/distributorSide/purchasingManagement/settlement'
        )
    },
    // 响应并生成采购单
    async toDeliver () {
      const body = {
        saleOrderId: this.id
      }
      const data = await this.$axios.$post(distributorSaleConfrim, body)
      if (data.code === '0') {
        this.$router.go(-1)
      }
    },
    // 搜索功能-点击查询
    searchForm (condition) {
      this.searchData = condition
      //
      if (this.tabIndex) {
        this.getInitializationList()
      } else {
        this.getList()
      }
    },
    // 点击重置
    resetForm (condition) {
      this.curPage = 1
      this.searchData = condition
    },
    // 初始化数据
    async getOrderStatusById () {
      await this.getList(0)
      this._globalBtns()
      this.getList()
    },
    /**
     * @param [Number] index
     * @desc 通过index选择请求方法 -- 获取--0:订单信息/1:收货信息
     */
    async getList (index = this.activeIndex) {
      if (![0, 1].includes(index)) return
      this.tableLoading = true
      // 表格字段名称 订单详情--getOrderList 发货详情--getDeliverList
      const requestList = [this.getOrderList, this.getDeliverList]
      const request = requestList[index]
      const { infoList, ...baseInfo } = await request()
      const cacheDeliverList = await this.getCacheDeliverList(3)// 获取缓存数据
      this.getSettleGetAmountofCache()

      Object.keys(baseInfo).forEach(key => {
        if (key === 'orderStatus') {
          this.orderStatus = baseInfo[key]
          baseInfo[key] = statusArr[baseInfo[key]]
        }
        this.$set(this.headerInfo, key, baseInfo[key] || '--')
      })
      this.tableLoading = false
      this.$set(this.orderLists, index, infoList.content)
      if (index === 1) {
        infoList.content.forEach(item => {
          this.$set(item, 'isEditInvoice', false)
        })
      }
      this.totalElements = infoList.totalElements || 0
      // --------根据暂存，反向勾选------
      await this.$nextTick()
      let cacheList = cacheDeliverList.payload.orderItemId
      if (this.orderLists[1]) {
        let list = this.orderLists[1]
        this.selectStatus = true
        list.forEach(item => {
          if (cacheList.includes(item.orderItemId)) {
            this.$refs.multipleTable.$refs.table.toggleRowSelection(item)
          }
        })
        this.selectStatus = false
      }
      // --------------------------
    },
    // 详情-销售单详情
    async getOrderList () {
      // 表格字段名称 订单详情--saleProductList 发货详情--waitDeliverProductList
      const url = distributorSaleOrderDetail
      const data = {
        page: this.curPage,
        pageSize: this.pageSize,
        saleOrderId: this.id,
        ...this.searchData
      }
      const res = await this.$axios.$post(url, data)
      const { saleProductList, ...baseInfo } = res.payload
      return { ...baseInfo, infoList: saleProductList }
    },
    // 详情-发货详情
    async getDeliverList () {
      const url = distributorSaleWait
      const data = {
        page: this.curPage,
        pageSize: this.pageSize,
        saleOrderId: this.id,
        waitDeliverType: '1',
        ...this.searchData
      }
      const res = await this.$axios.$post(url, data)
      const { waitDeliverProductList, ...baseInfo } = res.payload
      return { ...baseInfo, infoList: waitDeliverProductList }
    },
    // 详情-发货详情
    getCacheDeliverList (orderItemIdStatus, orderItemId = []) {
      const url = cacheInvoiceOrderItemInfo
      const data = {
        orderItemId,
        orderId: this.id, // 订单id
        orderItemIdStatus, // 订单明细状态0:删除缓存   ;1:存进缓存   2:用户全选  3：根据主键查询
        type: 'deliver'
      }
      return this.$axios.$post(url, data)
    },
    showPdfRegistion (id) {
      this.$axios({
        method: 'get',
        url: getCertificate,
        params: {
          id: id
        }
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        let url = obj.pictureUrl
        if (!url) {
          this.$message({
            type: 'warning',
            message: '获取失败，请在产品管理中维护该产品的注册证信息'
          })
        } else {
          this.$pdfViewer({ url, title: '注册证pdf预览' })
        }
      })
    },
    regisNoButton (data, str = 'registration') {
      const number = `${str}Number`
      const id = `${str}Id`
      if (data[number]) {
        return data[number]
      } else if (!data[number] && data[id]) {
        return '暂无注册证号'
      } else if (!data[number] && !data[id]) {
        return '暂无数据'
      }
    },
    // 批量添加发票号
    async batchAddInvoice () {
      const cacheDeliverList = await this.getCacheDeliverList(3)// 获取缓存数据
      this.getSettleGetAmountofCache()

      if (!cacheDeliverList.payload.orderItemId.length) {
        this.$confirm('此操作将对订单全部产品关联发票，是否继续？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(async () => {
            const data = await this.getCacheDeliverList(2)
            this.getSettleGetAmountofCache()

            if (data.code === '0') {
              this.$router.push({
                path: '/common/uploadInvoice',
                query: {
                  id: this.id,
                  type: 'deliver'
                }
              })
            }
          })
          .catch(() => {

          })
      } else {
        this.$router.push({
          path: '/common/uploadInvoice',
          query: {
            id: this.id,
            type: 'deliver'
          }
        })
      }
    },
    // 发货-单选走暂存
    async changeSelect (selection, row) {
      // 发货的勾选数据
      if (this.isDeliver && !this.selectStatus) {
        let status = selection.includes(row) ? 1 : 0
        let orderItemId = [row.orderItemId]
        const data = await this.getCacheDeliverList(status, orderItemId)
        this.getSettleGetAmountofCache()
      }
      // 响应的勾选数据
      if (this.isResponse) {
        this.selectList = selection
      }
    },
    // 发货-全选走暂存
    async changeSelectAll (selection) {
      // 发货的勾选数据
      if (this.isDeliver && !this.selectStatus) {
        let orderItemId = []
        if (selection.length) {
          orderItemId = selection.map(item => item.orderItemId)
        } else {
          orderItemId = this.orderLists[1].map(item => item.orderItemId)
        }
        const data = await this.getCacheDeliverList(selection.length ? 1 : 0, orderItemId)
        this.getSettleGetAmountofCache()
      }
      // 响应的勾选数据
      if (this.isResponse) {
        this.selectList = selection
      }
    },
    // 页码更改
    handleSizeChange (size) {
      this.pageSize = size
      this.getList()
    },
    // 切换不一样的页面,重置一切数据
    handleCurrentChange (curPage) {
      this.curPage = curPage
      this.getList()
    },

    // 循环分页的单独分页
    getChangePageList (page, pageSize, invoiceNo, index) {
      let data = {
        page: page,
        pageSize: pageSize,
        saleOrderId: this.id,
        invoiceNo: invoiceNo
      }
      this.$axios.$post(relevancePageRelList, data).then(res => {
        this.invoiceAssociatedList[index].productDetail = res.payload || []
      })
    },
    handleSizeChangeMultiple ($event, item, index) {
      item.Asize = $event
      let invoiceNo = item.content[0].invoiceNo
      let page = 1
      let pageSize = item.Asize
      this.getChangePageList(page, pageSize, invoiceNo, index)
    },
    handleCurrentChangeMultiple ($event, index) {
      // index当前的数据下标
      // $event当前的页码
      let invoiceNo = this.invoiceAssociatedList[index].invoiceNo
      let page = $event
      let pageSize = this.invoiceAssociatedList[index].productDetail.Asize || 20
      this.getChangePageList(page, pageSize, invoiceNo, index)
    },
    // 取消关联选中的数据
    changeSelectMultiple (val) {
      this.cancelRelevanceList = val
    }
  }
}
</script>

<style lang="less">
.distributor-settlement-change-box {
  position: absolute;
  overflow: auto;
  .change-container {
    // height: 100%;

    // overflow: auto;
    .custom-info {
      // margin: 0 0 20px 0;
    }
    .batch-btn.el-button span {
      color: white;
      margin-right: 0;
      font-size: 14px;
    }
    .batch-btn.el-button {
      position: absolute;
      right: 20px;
    }
    .pagination {
      padding-top: 10px;
      display: flex;
      justify-content: flex-end;
      padding-right: 0;
    }
    .invoice-associated-box {
      .invoice-associated-info {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 5px 0;
        p {
          margin-right: 20px;
        }
        .left-box {
          display: flex;
          align-items: center;
        }
      }
    }
    .batch-selection-supplier {
      margin: 20px 0;
      display: flex;
      justify-content: center;
      align-items: center;
      span {
        margin: 0 10px;
      }
    }
  }
}
</style>
